#pragma once
/*--------------------------------------------------------------------------------
 * Adaptive Intelligence - Foundation Framework Class Library
 * Version 2.00
 * 
 * Basic Safe Handle Class
 *      Provides a basic safe handle implementation.
 *------------------------------------------------------------------------------*/

/*--------------------------------------------------------------------------------
 * System Imports
 *------------------------------------------------------------------------------*/
#include "stdafx.h"
using namespace System;
using namespace System::Runtime;
using namespace System::Runtime::InteropServices;

namespace Adaptive
{
	namespace Win32
	{
		/// <summary>
		/// Provides a basic safe handle implementation.
		/// </summary>
		public ref class BasicSafeHandle : public SafeHandle 
		{
		public:
			/*--------------------------------------------------------------------------------
			 * Constructor / Dispose / Destructor Methods
			 *------------------------------------------------------------------------------*/
			#pragma region Constructor / Dispose / Destructor Methods
			/// <summary>
			/// Initializes a new instance of the class.
			/// </summary>
			/// <remarks>
			/// This is the default constructor.
			/// </remarks>
			BasicSafeHandle();
			/// <summary>
			/// Initializes a new instance of the class to the specified handle value.
			/// </summary>
			/// <param name="originalHandle">The original handle value.</param>
			BasicSafeHandle(IntPtr^ originalHandle);
			/// <summary>
			/// Initializes a new instance of the class to the specified handle value.
			/// </summary>
			/// <param name="originalHandle">The original handle value.</param>
			BasicSafeHandle(IntPtr originalHandle);
			#pragma endregion

			/*--------------------------------------------------------------------------------
			 * Public Properties
			 *------------------------------------------------------------------------------*/
			#pragma region Public Properties
			/// <summary>
			/// Gets the underlying handle value.
			/// </summary>
			/// <value>
			/// An <see cref="IntPtr"/> value indicating the underlying handle.
			/// </value>
			property IntPtr HandleValue { IntPtr get(); }
			/// <summary>
			/// Gets a value indicating whether the underlying handle is invalid.
			/// </summary>
			/// <value>
			/// <b>true</b> if the underlying handle value is an invalid handle or null value;
			/// otherwise, <b>false</b>.
			/// </value>
			property bool IsInvalid { bool virtual get() override; }
			#pragma endregion
 
		protected:
			/*--------------------------------------------------------------------------------
			 * Constructor / Dispose / Destructor Methods
			 *------------------------------------------------------------------------------*/
			#pragma region Constructor / Dispose / Destructor Methods
			/// <summary>
			/// Initializes a new instance of the class to the specified unmanaged handle value.
			/// </summary>
			/// <param name="originalHandle">The original handle value.</param>
			BasicSafeHandle(HANDLE originalHandle);

			/*--------------------------------------------------------------------------------
			 * Protected Methods / Event Methods
			 *------------------------------------------------------------------------------*/
			#pragma region Protected Methods / Event Methods
			/// <summary>
			/// Releases the underlying handle value.
			/// </summary>
			virtual bool ReleaseHandle() override;
			#pragma endregion
		};
	}
}